package 常见算法.非视频算法;

/**
 * @Date 2024/6/4 10:21
 * @description: 旋转矩阵90度
 * .                https://leetcode.cn/problems/rotate-image/description/
 * @Author LittleNight
 */
public class likou48 {
    public static void main(String[] args) {
        System.out.println("ceshi");
        System.out.println("ceshi1");
        int i = 10;
        if(i == 10)
            System.out.println(i + ": i");
        System.out.println("ceshi2");
        System.out.println("ceshi3");
        System.out.println("ceshi4");
    }

    public void rotate(int[][] matrix) {
        int length = matrix.length;
        // 1. 先把上下行进行交换
        for (int i = 0; i < length / 2; i++) {
            // 类似于俩个数进行交换, 一定要非常熟悉
            // length - 1 表示最后一行, length - 1 - i 表示最后一行 - i
            int[] tmp = matrix[i];
            matrix[i] = matrix[length - 1 - i];
            matrix[length - 1 - i] = tmp;
        }

        // 2. 每个元素在按照对角线进行交换
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < length; j++) {
                int tmp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = tmp;
            }
        }
    }
}
